package com.example.superoa.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.example.superoa.model.pojos.Contract;
import com.example.superoa.model.service.ContractService;
import com.example.superoa.model.vo.ContractVo;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

@Controller
public class ContractController {
		@Autowired
		private ContractService contractservice;
		//合同管理
		@RequestMapping("ljj-contract")
		public void Contract() {
		}
		
		@RequestMapping("contract-list")
		@ResponseBody
		public List<ContractVo> ContractList(){
			return contractservice.contractAll();
		}
		
		/*合同详情*/
		@RequestMapping("ljj-contract-xq")
		public void xq() {
			
		}
		@RequestMapping("contractaaaaa")
		@ResponseBody
		public Map<String,Object> show(int page,int rows) {
			Map<String,Object> map = new HashMap<>();
			//先分页
			Page<Object> pg = PageHelper.startPage(page, rows);
			
			JSONArray i=contractservice.select();
			//总记录
			map.put("total", pg.getTotal());
			//页内容
			map.put("rows", i);
			return map;
		}
		@RequestMapping("select_contractaaaaa")
		@ResponseBody
		public JSONArray select() {
			return contractservice.select();
		}
		
		//合同获取编辑数据
		@RequestMapping("contract-bjsj")
		@ResponseBody
		public Contract ContractBjsj(int contreact_id,Model model) {
			System.err.println(contractservice.contreactById(contreact_id).getContract_TypeName());
			return contractservice.contreactById(contreact_id);
		}
		//合同修改
		@PostMapping("xiugai-contract")
		@ResponseBody
		public void XiugaiContract(Contract contreact_id) {
			System.err.println(contreact_id);
			contractservice.contreactbj(contreact_id);
		}
		//模糊查询
		@RequestMapping("select-contract")
		@ResponseBody
		public /*Map<String,Object>*/JSONArray recruitselect (@Param("contract_TypeName")String contract_TypeName/*,int page,int rows*/){
			/*System.err.println(contract_TypeName);
			Map<String,Object> map=new HashMap<>();
			//先分页
			Page<Object> pg = PageHelper.startPage (page,rows);
			JSONArray list = contractservice.contractselect(contract_TypeName);
			//总记录
			map.put("total", pg.getTotal());
			//页内容
			map.put("rows", list);*/
			return contractservice.contractselect(contract_TypeName);
		}
		
		@PostMapping("qd-contract")
		@ResponseBody
		public void Contractstate(String contreact_qdstate,int contreact_id) {
			contractservice.Contractstate("已签订", contreact_id);
		}
}
